import 'package:flutter/material.dart';
import 'package:lai_zhan/common/style/AppStyle.dart';
import 'dart:io';
enum ImageTpye {
  asset,
  network,
  file
}

/**
 * 头像
 */
class HeadPortrait extends StatelessWidget {

  ImageTpye imageTpye;
  String url;
  VoidCallback onClick;

  HeadPortrait({this.imageTpye = ImageTpye.asset, this.url = 'lib/images/man.png',this.onClick});

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    Widget image;
    switch(imageTpye){
      case ImageTpye.asset:
        image = new Image.asset(url,width: AppSize.userIconSize,height: AppSize.userIconSize,fit: BoxFit.cover,);
        break;
      case ImageTpye.file:
        File file = new File(url);
        file.exists().then((isExists){
          image = isExists?new Image.file(file,width: AppSize.userIconSize,height: AppSize.userIconSize,fit: BoxFit.cover,):
          new Image.asset('lib/images/man.png',width: AppSize.userIconSize,height: AppSize.userIconSize,fit: BoxFit.cover,);
        });
        break;
      case ImageTpye.network:
        image = new Image.network(url,width: AppSize.userIconSize,height: AppSize.userIconSize,fit: BoxFit.cover,);
        break;
    }
    return new GestureDetector(child: ClipOval(
      child: new Container(
        child: image,
        color: Color(AppColors.primaryColor),
      ),
    ),
      onTap: (){
        this.onClick?.call();
      },
    );
  }

}